package com.xja.dubbo.controller;

import com.xja.dubbo.entity.Easybuy_seller;
import com.xja.dubbo.service.SellerService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author ycz
 * @create 2021-12-14-16:09
 */
@Controller
@RequestMapping("seller")
public class SellerController {
    private Logger logger = LoggerFactory.getLogger(SellerController.class);

    @Reference(url = "dubbo://localhost:20880")
    private SellerService sellerService;

    @RequestMapping("login")
    public String login(Easybuy_seller seller, HttpSession session){

        try {
            logger.info("卖家登录："+seller);
            System.out.println(seller);
            Easybuy_seller loginUser = sellerService.findSellerByName(seller.getName());
            if(loginUser==null || !loginUser.getPassword().equals(seller.getPassword())){
                session.setAttribute("msg", "用户名或密码错误");
                return "login";
            }
            session.removeAttribute("msg");
            session.setAttribute("loginUser", loginUser);
            return "redirect:/main.html";
        }catch (Exception e){
            logger.error("卖家登录", e);
        }
        return "redirect:/error.html";
    }
}
